package com.zjdiepu.www.service.partner.impl;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.diepu.www.client.proxy.hzicbc.request.CreditResultRequest;
import com.diepu.www.client.proxy.hzicbc.request.ObtainFileListRequest;
import com.diepu.www.client.proxy.partner.common.ObtainFileListResponse;
import com.diepu.www.client.proxy.partner.request.own.DiepuIcbcQryMarginRequest;
import com.zjdiepu.www.config.ClientConfig;
import com.zjdiepu.www.consts.PartnerService;
import com.zjdiepu.www.net.HttpClient;
import com.zjdiepu.www.response.BooleanResponse;
import com.zjdiepu.www.security.base.enums.ResultCode;
import com.zjdiepu.www.security.client.encode.BaseEncryptService;
import com.zjdiepu.www.security.exception.BasePartnerException;
import com.zjdiepu.www.security.server.core.Partners;
import com.zjdiepu.www.service.partner.IcbcApiService;
@Service
public class IcbcApiServiceImpl  extends BaseEncryptService implements IcbcApiService{

	private Partners partner = Partners.DIE_PU;
	
	@Override
	public boolean diepuIcbcQryMargin(DiepuIcbcQryMarginRequest diepuIcbcQryMarginRequest)throws BasePartnerException
	{
		
		String signEncrypt = signEncrypt(diepuIcbcQryMarginRequest, partner);
		if(StringUtils.isBlank(signEncrypt)) 
		{
			throw new BasePartnerException(ResultCode.FAIL_PARAM_EMPTY);
		}
		String applyDiviStatusJson = HttpClient.postJson(ClientConfig.getPartnerGateWay(partner) + PartnerService.DIEPUICBCQRYMARGIN, signEncrypt);
		BooleanResponse booleanResponse = valdateDencrypt(applyDiviStatusJson, BooleanResponse.class, partner);
		return booleanResponse.getResult();
	}

	@Override
	public boolean creditResult(CreditResultRequest creditResultRequest)throws BasePartnerException
	{
		String signEncrypt = signEncrypt(creditResultRequest, partner);
		if(StringUtils.isBlank(signEncrypt)) 
		{
			throw new BasePartnerException(ResultCode.FAIL_PARAM_EMPTY);
		}
		String applyDiviStatusJson = HttpClient.postJson(ClientConfig.getPartnerGateWay(partner) + PartnerService.DIEPUCREDITRESULT, signEncrypt);
		BooleanResponse booleanResponse = valdateDencrypt(applyDiviStatusJson, BooleanResponse.class, partner);
		return booleanResponse.getResult();
	}

	@Override
	public ObtainFileListResponse obtainFileList(ObtainFileListRequest obtainFileListRequest) throws BasePartnerException{
		
		String signEncrypt = signEncrypt(obtainFileListRequest, partner);
		if(StringUtils.isBlank(signEncrypt)) {
			throw new BasePartnerException(ResultCode.FAIL_PARAM_EMPTY);
		}
		String applyDiviStatusJson = HttpClient.postJson(ClientConfig.getPartnerGateWay(partner) + PartnerService.OBTAINFILELIST, signEncrypt);
		ObtainFileListResponse response = valdateDencrypt(applyDiviStatusJson, ObtainFileListResponse.class, partner);
		return response;
	}
}
